<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-4-7
 * Time: 14:40
 */

namespace common\models;
use yii\db\ActiveRecord;
use yii\data\ActiveDataProvider;

class Userr extends ActiveRecord
{
    public static function tableName()
    {
        return 'userr';
    }
    public function rules()
    {
        return [
            [['id','status'], 'integer'],
            [['username', 'openid', 'wxname'], 'string'],
        ];
    }
    //查询
    public function search($params)
    {
        //首先我们先获取一个ActiveQuery
        $query = self::find();
        //然后创建一个ActiveDataProvider对象
        $provider = new ActiveDataProvider([
            //为ActiveDataProvider对象提供一个查询对象
            'query' => $query,
            //设置分页参数
            'pagination' => [
                //分页大小
                'pageSize' => 3,
                //设置地址栏当前页数参数名
                'pageParam' => 'p',
                //设置地址栏分页大小参数名
                'pageSizeParam' => 'pageSize',
            ],
            //设置排序
            'sort' => [
                //默认排序方式
                'defaultOrder' => [
                    'id' => SORT_DESC,
                ],

            ],
        ]);

        //如果验证没通过，直接返回
        if (!($this->load($params) && $this->validate())) {
            return $provider;
        }

        //增加过滤条件
        $query->andFilterWhere(['id' => $this->id]);
        $query->andFilterWhere(['username' => $this->username]);
        $query->andFilterWhere(['wxname' => $this->wxname]);
        $query->andFilterWhere(['status' => $this->status]);
        return $provider;
    }

}